//
//  SHScaleAnimatorCoordinator.m
//  Tradeaider
//
//  Created by 王方伟 on 2017/7/12.
//  Copyright © 2017年 Shinyhub. All rights reserved.
//

#import "SHScaleAnimatorCoordinator.h"

@interface SHScaleAnimatorCoordinator ()
@property (weak, nonatomic) UIView *maskView;
@property (strong, nonatomic) UIView *currentHiddenView;
@end

@implementation SHScaleAnimatorCoordinator


- (void)updateCurrentHiddenView:(UIView *)view{
    _currentHiddenView.hidden = FALSE;
    _currentHiddenView = view;
    view.hidden = TRUE;
}

- (void)setAlpha:(CGFloat)alpha{
    _maskView.alpha = alpha;
}

- (void)presentationTransitionWillBegin{
    [super presentationTransitionWillBegin];
    UIView *containerView = self.containerView;
    UIView *maskView = [[UIView alloc] init];
    maskView.backgroundColor = [UIColor blackColor];
    maskView.frame = containerView.bounds;
    [containerView addSubview:maskView];
    _maskView = maskView;
    
    self.maskView.alpha = 0.0f;
    _currentHiddenView.hidden = TRUE;
    [self.presentedViewController.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
        self.maskView.alpha = 1.0f;
    } completion:nil];
}

- (void)dismissalTransitionWillBegin{
    [super dismissalTransitionWillBegin];
    _currentHiddenView.hidden = TRUE;
    [self.presentedViewController.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
        self.maskView.alpha = 0.0f;
        
    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
        _currentHiddenView.hidden = FALSE;
    }];
}
@end
